package library

import (
	"log"
	"syproxy/protocol"
	"syproxy/service"
)

// HandleReadServer 处理读
func HandleRead(content *protocol.Pack, s, c *service.Service) {
	str := string(content.Data)
	// 如果是接受到心跳包直接跳过
	if str == "ping" {
		log.Println("received ping")
		s.Conn.Write([]byte("pong"))
		return
	}
	if str == "pong" {
		log.Println("received pong")
		return
	}
	if str == "open" {
		s.Open <- content.Id
		return
	}
	if str == "close" {
		if s != nil && c != nil {
			s.CloseOther <- c.Id
		}
		return
	}

	if c != nil {
		c.WriteRaw(content.Data)
	}
}
